
*** IMPORTING DATASETS ***

clear
set more off, perm
set scrollbufsize 300000

*** Import Study Replication Dataset (Adjust 'User' / File Location Accordingly)

use "C:\Users\...FamilyMatters_Replication_Raw.dta", clear


** Note, the above is a reduced and merged version of the 'Intergenpol-GB' (Aug 2022) and the British Election Study Internet Panel Wave 23 (May 2022) datasets.

** For the original, full datasets (with observations not used in the present study), as well as their associated codebooks, please see:

*** Intergenpol-GB (v.1.1): Grant, Z., J. Green, G. Evans. (2023). Study of Intergenerational Political Preferences in Great Britain [INTERGENPOL-GB], Vers.1.1. DOI: 10.7910/DVN/OYJHAM, Harvard Dataverse. Available at: https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi%3A10.7910%2FDVN%2FOYJHAM. Accessed: 09/10/23.

*** British Election Study Internet Panel, Wave 23 (v.1): Fieldhouse, E., J. Green, G. Evans, J. Mellon & C. Prosser, J. Bailey. (2022). British Election Study Internet Panel Waves 1-23. DOI: 10.5255/UKDA-SN-8810-1. Available at: https://www.britishelectionstudy.com/data-objects/panel-study-data/. Accessed:  09/10/23.




***************************************  PART 1: VARIABLE RE-CODING (Consult 'FamilyMatters_ReplicationPart2_Analysis.do' & 'FamilyMatters_ReplicationData_Cleaned.dta' if you want to skip this stage) *******************************************

************************************************ AGE

* Age Grouped in Decades
recode age_yg (18/29 = 1 "18-29") (30/39 = 2 "30-39") (40/49 = 3 "40-49") (50/59 = 4 "50-59") (60/69 = 5 "60-69") (70/99 = 6 "70+") (else=.), gen(agegroup_decades)
label var agegroup_decades "Age Groups: Decades (No Impute)"

* Linear Age, Expressed in Decades
gen age10 = age_yg / 10
label var age10 "Age (in Decades, No Impute)"

* Dummy Variable = 1 if Aged 60+
gen aged60plus =.
label var aged60plus "Dummy Var: R is Aged 60+"
replace aged60plus = 1 if inrange(age_yg,60,99)
replace aged60plus = 0 if inrange(age_yg,18,59)



************************************************ GENDER

* Dummy Variable = 1 if Female
recode gender_yg (1 = 0 "Male") (2 = 1 "Female") (else=.), gen(female)
label var female "Female Dummy (No Impute)"



************************************************ ETHNICITY

* Ethnicity = Missing if DK
gen ethnicity_NA =. 
label var ethnicity_NA "Ethnicity (No Impute)"
label define ethnic 1 "White British" 2 "White Other" 3 "Asian" 4 "Afro-Caribbean" 5 "Other Non-White", replace
label values ethnicity_NA ethnic
replace ethnicity_NA = 1 if inlist(p_ethnicity,1)
replace ethnicity_NA = 2 if inlist(p_ethnicity,2)
replace ethnicity_NA = 3 if inlist(p_ethnicity,5,7,8,9,10,14)
replace ethnicity_NA = 4 if inlist(p_ethnicity,3,4,11,12,13)
replace ethnicity_NA = 5 if inlist(p_ethnicity,6,15)


* Ethnicity = '5' ('Other') if DK
gen ethnicity_imputed =. 
label var ethnicity_imputed "Ethnicity ('Other' if NA)"
label define ethnic 1 "White British" 2 "White Other" 3 "Asian" 4 "Afro-Caribbean" 5 "Other/NA", replace
label values ethnicity_imputed ethnic
replace ethnicity_imputed = 1 if inlist(p_ethnicity,1)
replace ethnicity_imputed = 2 if inlist(p_ethnicity,2)
replace ethnicity_imputed = 3 if inlist(p_ethnicity,5,7,8,9,10,14)
replace ethnicity_imputed = 4 if inlist(p_ethnicity,3,4,11,12,13)
replace ethnicity_imputed = 5 if ethnicity_imputed ==. 



************************************************ EDUCATION

* Education = Missing if DK
gen education_NA =. 
label var education_NA "Highest Educational Qualification (No Impute)"
label define education_NA 1 "No Formal Qualifications" 2 "GCSEs or Equivalent / Trade Certificates" 3 "A-Levels or Higher Non-Degree (inc. Diplomas)" 4 "BA Degree +", replace
label values education_NA education_NA
replace education_NA = 1 if educlevel_yg == 1 
replace education_NA = 2 if inrange(educlevel_yg,2,10)
replace education_NA = 3 if inlist(educlevel_yg,11,12,15,18)
replace education_NA = 4 if inlist(educlevel_yg,13,14,16,17)

* University Education Dummy Variable = Missing if DK
gen unidegree_NA =.
label var unidegree_NA "University Degree Dummy (No Impute)"
label define unidegree_NA 0 "No BA Degree (or Equiv)" 1 "BA Degree +", replace
label values unidegree_NA unidegree_NA
replace unidegree_NA = 0 if inrange(education_NA,1,3)
replace unidegree_NA = 1 if education_NA == 4

* Education = If Missing, Imputed Using Data from Other Variables in the BES (e.g. age left school, whether currently attending univerity etc.)
gen education_imputed =. 
label var education_imputed "Highest Educational Qualification (Imputed if NA)"
label define education_imputed 1 "No Formal Qualifications" 2 "GCSEs or Equivalent / Trade Certificates" 3 "A-Levels or Higher Non-Degree (inc. Diplomas)" 4 "BA Degree +" 99 "NA", replace
label values education_imputed education_imputed

replace education_imputed = 1 if educlevel_yg == 1 
replace education_imputed = 2 if inrange(educlevel_yg,2,10)
replace education_imputed = 3 if inlist(educlevel_yg,11,12,15,18)
replace education_imputed = 4 if inlist(educlevel_yg,13,14,16,17)
replace education_imputed = 1 if education_imputed ==. & p_education == 1 
replace education_imputed = 2 if education_imputed ==. & inrange(p_education,2,10)
replace education_imputed = 3 if education_imputed ==. & inlist(p_education,11,12,15,18)
replace education_imputed = 4 if education_imputed ==. & inlist(p_education,13,14,16,17)
replace education_imputed = 1 if education_imputed ==. & educyears_yg == 1
replace education_imputed = 2 if education_imputed ==. & educyears_yg == 2
replace education_imputed = 3 if education_imputed ==. & inlist(educyears_yg,3,4) 
replace education_imputed = 4 if education_imputed ==. & inlist(educyears_yg,5,6) 
replace education_imputed = 3 if education_imputed ==. & inlist(p_education_age,3,4) 
replace education_imputed = 4 if education_imputed ==. & inlist(p_education_age,5,6) 
replace education_imputed = 99 if education_imputed ==. //* 4 remaining code as NA

* University Education Dummy Variable = If Missing, Imputed Using Data from Other Variables in the BES (e.g. age left school, whether currently attending university etc.)
recode education_imputed (1/3 = 0 "No Degree") (4 = 1 "Has Degree or Equivalent") (else=.), gen(unidegree_imputed)
replace unidegree_imputed = 0 if unidegree_imputed ==. //* 4 NA coded as non-grads
label var unidegree_imputed "University Degree Dummy (Imputed if NA)"



************************************************ EMPLOYMENT STATUS

* Employment Status 
gen workstatus =.
label var workstatus "Employment Status (No Impute)"
label define workstatus 1 "FT Worker" 2 "PT Worker" 3 "Retired" 4 "Unemployed" 5 "Other", replace
label values workstatus workstatus

replace workstatus = 1 if workstatus_yg == 1
replace workstatus = 2 if inrange(workstatus_yg,2,3)
replace workstatus = 3 if workstatus_yg == 5
replace workstatus = 4 if workstatus_yg == 6
replace workstatus = 5 if inlist(workstatus_yg,4,7,8)  



************************************************ SOCIAL CLASS

* UK NRS Social Grade Classification (Chief HH Income Earner)
rename socialgrade_yg socialgrade_NA
label var socialgrade_NA "NRS Social Grade of Chief Income Earner in HH. Main occupational class proxy."

* UK NS-SEC Occupational Social Class Classification, If Missing Coded as '98' or '99' (Other/DK), Depending on Whether a FT Worker
gen nssec_occupclass_NA =.
label var nssec_occupclass_NA "Compressed NS-SEC Class Classification (No Impute)"
label define nssec_occupclass_NA 11 "Employers in Large Orgs + Higher Managerial" 12 "Higher Professionals" 20 "Lower Professionals + Managerial" 30 "Intermediate Occupations" 40 "Employers in Small Orgs + Own Account" ///
50 "Lower Supervisory + Technical Occs" 60 "Semi-Routine Occs" 70 "Routine Occs" 98 "NA - FT Employment" 99 "NA - Not in FT Worker" , replace
label values nssec_occupclass_NA nssec_occupclass_NA
replace nssec_occupclass_NA = ns_sec_analytic
replace nssec_occupclass_NA = 98 if nssec_occupclass ==. & workstatus == 1  //* 168
replace nssec_occupclass_NA = 99 if nssec_occupclass ==. & inrange(workstatus,2,6) //* 548



************************************************ REGION

* UK Region of Respondent (Simplified)
gen region_NA =.
label variable region_NA "Region in Britain - 7 Categories (No Impute)"	
label define region_NA 1 "Northern England" 2 "Midlands England" 3 "South England (exc. London)" 4 "London" 5 "Wales" 6 "Scotland"
label values region_NA region_NA
replace region_NA = 1 if inrange(region_yg,1,3)
replace region_NA = 2 if inrange(region_yg,4,5)	
replace region_NA = 3 if inlist(region_yg,6,8,9)		
replace region_NA = 4 if region_yg == 7	
replace region_NA = 5 if region_yg == 10		
replace region_NA = 6 if region_yg == 11		



************************************************ HOUSING TENURE & VALUE

* Housing Tenure (Long)
gen housinglong_NA =.
label var housinglong_NA "Housing Tenure - 7 Categories (No Impute)"
label define  housinglong_NA 1 "Own Outright" 2 "Own with Mortgage  (or Part Ownersip)" 3 "Rent from Local Authority" 4 "Rent Privately" 5 "Rent from Housing Association" 6 "Live with Family/Friends" 7 "Other", replace
label values housinglong_NA housinglong_NA
replace housinglong_NA = 1 if housingtenure_yg == 1
replace housinglong_NA = 2 if housingtenure_yg == 2 | housingtenure_yg == 3
replace housinglong_NA = 3 if housingtenure_yg == 5
replace housinglong_NA = 4 if housingtenure_yg == 4 
replace housinglong_NA = 5 if housingtenure_yg == 6 
replace housinglong_NA = 6 if housingtenure_yg == 7 | housingtenure_yg == 8
replace housinglong_NA = 7 if housingtenure_yg == 9	

* Housing Tenure (Simplified)
gen housingshort_NA =.
label var housingshort_NA "Housing Tenure - 4 Categories (No Impute)"
label define housingshort_NA 1 "Own Outright" 2 "Own with Mortgage (or Part Ownership)" 3 "Rent" 4 "Other", replace
label values housingshort_NA housingshort_NA
replace housingshort_NA = 1 if housinglong == 1
replace housingshort_NA = 2 if housinglong == 2 
replace housingshort_NA = 3 if inrange(housinglong,3,5)
replace housingshort_NA = 4 if inrange(housinglong,6,7)

* Dummy Variable = 1 if House Value = DK
gen houseNA =.
replace houseNA = 1 if homeAmtb == 9999
replace houseNA = 0 if homeAmtb != 9999

* Recode House Value = Missing if House Value = DK; = £0 if Respondent Does Not Own the Property
replace homeAmtb =. if homeAmtb == 9999
replace homeAmtb = 0 if inrange(housingshort,3,4)
rename homeAmtb housevalue_NA
label variable housevalue_NA  "Value of House (Non-Owners = 0, No Impute)"

* Impute Housevalue Based on Regional Median (ie. for London, South West England, North East England, Wales etc.) if House Value = DK & Respondent Owns the Property
gen housevalue_imputed = housevalue_NA
replace housevalue_imputed = 4 if  housevalue_imputed ==. & inrange(housingshort,1,2) & region_yg == 1
replace housevalue_imputed = 4 if  housevalue_imputed ==. & inrange(housingshort,1,2) & region_yg == 2
replace housevalue_imputed = 4 if  housevalue_imputed ==. & inrange(housingshort,1,2) & region_yg == 3
replace housevalue_imputed = 5 if  housevalue_imputed ==. & inrange(housingshort,1,2) & region_yg == 4
replace housevalue_imputed = 5 if  housevalue_imputed ==. & inrange(housingshort,1,2) & region_yg == 5
replace housevalue_imputed = 7 if  housevalue_imputed ==. & inrange(housingshort,1,2) & region_yg == 6
replace housevalue_imputed = 8 if  housevalue_imputed ==. & inrange(housingshort,1,2) & region_yg == 7
replace housevalue_imputed = 7 if  housevalue_imputed ==. & inrange(housingshort,1,2) & region_yg == 8
replace housevalue_imputed = 6 if  housevalue_imputed ==. & inrange(housingshort,1,2) & region_yg == 9
replace housevalue_imputed = 4 if  housevalue_imputed ==. & inrange(housingshort,1,2) & region_yg == 10
replace housevalue_imputed = 4 if  housevalue_imputed ==. & inrange(housingshort,1,2) & region_yg == 11
label variable housevalue_imputed  "Value of House (Non-Owners = 0, Imputed if NA)"
label define homevalue_15cat  0 "Non-Owner" 1 "£0-49,999k" 2 "£50k - £99,999" 3 "£100,000 - £149,999" 4 "£150,000 - £199,999" 5 "£200,000 - £249,999"  6 "£250,000 - £299,999" 7 "£300,000 - £399,999" 8 "£400,000 - £499,999" ///
                            9 "£500,000 - £599,999" 10 "£600,000 - £699,999" 11 "£700,000 - £799,999" 12 "£800,000 - £899,999" 13 "£900,000 - £999,999" 14 "£1,000,000+", replace
label values housevalue_NA housevalue_imputed homevalue_15cat

* House Value, Linear (= Missing if House Value = DK; = £0 if Respondent Does Not Own the Property)
gen HHvaluelinear_NA =.
label var HHvaluelinear_NA "Value of House (No Impute, Non-Owners = 0)"
replace HHvaluelinear_NA = 0      if housevalue_NA == 0
replace HHvaluelinear_NA = 25000  if housevalue_NA == 1
replace HHvaluelinear_NA = 75000  if housevalue_NA == 2
replace HHvaluelinear_NA = 125000 if housevalue_NA == 3
replace HHvaluelinear_NA = 175000 if housevalue_NA == 4
replace HHvaluelinear_NA = 225000 if housevalue_NA == 5
replace HHvaluelinear_NA = 275000 if housevalue_NA == 6
replace HHvaluelinear_NA = 350000 if housevalue_NA == 7
replace HHvaluelinear_NA = 450000 if housevalue_NA == 8
replace HHvaluelinear_NA = 550000 if housevalue_NA == 9
replace HHvaluelinear_NA = 650000 if housevalue_NA == 10
replace HHvaluelinear_NA = 750000 if housevalue_NA == 11
replace HHvaluelinear_NA = 850000 if housevalue_NA == 12
replace HHvaluelinear_NA = 950000 if housevalue_NA == 13
replace HHvaluelinear_NA = 1000000 if housevalue_NA == 14

* House Value, Linear (= Imputed Using Regional Median if House Value = DK; = £0 if Respondent Does Not Own the Property)
gen HHvaluelinear_impute =.
label var HHvaluelinear_impute "Value of House (Imputed if NA, Non-Owners = 0)"
replace HHvaluelinear_impute = 0      if housevalue_impute == 0
replace HHvaluelinear_impute = 25000  if housevalue_impute == 1
replace HHvaluelinear_impute = 75000  if housevalue_impute == 2
replace HHvaluelinear_impute = 125000 if housevalue_impute == 3
replace HHvaluelinear_impute = 175000 if housevalue_impute == 4
replace HHvaluelinear_impute = 225000 if housevalue_impute == 5
replace HHvaluelinear_impute = 275000 if housevalue_impute == 6
replace HHvaluelinear_impute = 350000 if housevalue_impute == 7
replace HHvaluelinear_impute = 450000 if housevalue_impute == 8
replace HHvaluelinear_impute = 550000 if housevalue_impute == 9
replace HHvaluelinear_impute = 650000 if housevalue_impute == 10
replace HHvaluelinear_impute = 750000 if housevalue_impute == 11
replace HHvaluelinear_impute = 850000 if housevalue_impute == 12
replace HHvaluelinear_impute = 950000 if housevalue_impute == 13
replace HHvaluelinear_impute = 1000000 if housevalue_impute == 14

* House Value, Logged Version (for Imputed and Non-Imputed Versions, Respectively)
gen housevalue_logged_imputed = ln(HHvaluelinear_impute + 1)
label var housevalue_logged_imputed "Logged House Value (Non-Owners = 0, Imputed if NA)"

gen housevalue_logged_NA = ln(HHvaluelinear_NA + 1)
label var housevalue_logged_NA "Logged House Value (Non-Owners = 0, No Impute)"


* House Ownership + Value Groups, Tercile Version (for Imputed and Non-Imputed Versions, Respectively)
xtile houseterciles_imputed = HHvaluelinear_impute [pweight= weight] if HHvaluelinear_imp !=0, n(3) //* Terciles 
gen homevaluegrp_imputed =.
label var homevaluegrp_imputed   "Ownership + Value of House (Imputed if NA)"
label define homevaluegrp_imputed   1 "No Property" 2 "Own - 1st Tercile Value (<£250k)" 3 "Own - 2nd Tercile Value (£250k - £400k)" 4 "Own - 3rd Tercile Value (£400k <)", replace
label values homevaluegrp_imputed   homevaluegrp_imputed 
replace homevaluegrp_impute  = 1 if inrange(housingshort,3,4)
replace homevaluegrp_impute  = 2 if inrange(housingshort,1,2) & houseterciles_impute == 1
replace homevaluegrp_impute  = 3 if inrange(housingshort,1,2) & houseterciles_impute == 2
replace homevaluegrp_impute  = 4 if inrange(housingshort,1,2) & houseterciles_impute == 3

xtile houseterciles_NA = HHvaluelinear_NA [pweight= weight] if HHvaluelinear_NA  !=0, n(3) //* Terciles 
gen homevaluegrp_NA =.
label var homevaluegrp_NA   "Ownership + Value of House (No Impute if NA)"
label define homevaluegrp_NA   1 "No Property" 2 "Own - 1st Tercile Value (<£250k)" 3 "Own - 2nd Tercile Value (£250k - £400k)" 4 "Own - 3rd Tercile Value (£400k <)", replace
label values homevaluegrp_NA   homevaluegrp_NA 
replace homevaluegrp_NA  = 1 if inrange(housingshort,3,4)
replace homevaluegrp_NA  = 2 if inrange(housingshort,1,2) & houseterciles_NA == 1
replace homevaluegrp_NA  = 3 if inrange(housingshort,1,2) & houseterciles_NA == 2
replace homevaluegrp_NA  = 4 if inrange(housingshort,1,2) & houseterciles_NA == 3

drop houseNA housevalue_imputed housevalue_NA



************************************************ RELATIONSHIP STATUS 

* Dummy Variable = 1 if Living with a Partner (Married or Otherwise)
gen partnered_NA =.
label var partnered_NA "Married, Civil Partnership or Living as Married Dummy (No Impute)"
replace partnered_NA = 1 if inlist(maritalstatus_yg,1,2,7)
replace partnered_NA = 0 if inlist(maritalstatus_yg,3,4,5,6,.)
replace partnered_NA = 0 if partnered_NA == .



************************************************ HOUSEHOLD INCOME (RAW + EQUIVALISED VERSIONS)

* Raw Household Income Groups = Missing if DK
gen HHincomegrp_NA =.
label variable HHincomegrp_NA "Household Income - Raw Intervals (No Impute)"
label define HHincomegrp 1 "<£5,000" 2 "£5,000 - £9,999" 3 "£10,000 - £14,999" 4 "£15,000 - £19,999" 5 "£20,000 - £24,999"  6 "£25,000 - £29,999" 7 "£30,000 - £34,999" 8 "£35,000 - £39,999" ///
                            9 "£40,000 - £44,999" 10 "£45,000 - £49,999" 11 "£50,000 - £59,999" 12 "£60,000 - £69,999" 13 "£70,000 - £99,999" 14 "£100,000 - £149,999" 15 "£150,000+", replace
label values HHincomegrp_NA HHincomegrp
replace HHincomegrp_NA = incomehousehold_yg if inrange(incomehousehold_yg,1,15)

* Linear Raw Household Income = Missing if DK
gen HHincomelinear_NA =.
label var HHincomelinear_NA "Household Income (No Impute)"
replace HHincomelinear_NA = 2500 if HHincomegrp == 1
replace HHincomelinear_NA = 7500 if HHincomegrp == 2
replace HHincomelinear_NA = 12500 if HHincomegrp == 3
replace HHincomelinear_NA = 17500 if HHincomegrp == 4
replace HHincomelinear_NA = 22500 if HHincomegrp == 5
replace HHincomelinear_NA = 27500 if HHincomegrp == 6
replace HHincomelinear_NA = 32500 if HHincomegrp == 7
replace HHincomelinear_NA = 37500 if HHincomegrp == 8
replace HHincomelinear_NA = 42500 if HHincomegrp == 9
replace HHincomelinear_NA = 47500 if HHincomegrp == 10
replace HHincomelinear_NA = 55000 if HHincomegrp == 11
replace HHincomelinear_NA = 65000 if HHincomegrp == 12
replace HHincomelinear_NA = 85000 if HHincomegrp == 13
replace HHincomelinear_NA = 125000 if HHincomegrp == 14
replace HHincomelinear_NA = 150000 if HHincomegrp == 15

* Household Income Groups, if Missing Impute Based on a) Alternative Earlier Estimates of HH Income from BES; b) Single Imputation using Gender, Relationship, Age, Employment Status, Occupational Class, Region and Education
gen HHincomegrp_imputed =.
label variable HHincomegrp_imputed "Household Income - Raw Intervals (Imputed if NA)"
label define HHincomegrp 1 "<£5,000" 2 "£5,000 - £9,999" 3 "£10,000 - £14,999" 4 "£15,000 - £19,999" 5 "£20,000 - £24,999"  6 "£25,000 - £29,999" 7 "£30,000 - £34,999" 8 "£35,000 - £39,999" ///
                            9 "£40,000 - £44,999" 10 "£45,000 - £49,999" 11 "£50,000 - £59,999" 12 "£60,000 - £69,999" 13 "£70,000 - £99,999" 14 "£100,000 - £149,999" 15 "£150,000+", replace
label values HHincomegrp_imputed HHincomegrp
replace HHincomegrp_imputed = incomehousehold_yg if inrange(incomehousehold_yg,1,15)
replace HHincomegrp_imputed = p_gross_household if HHincomegrp_imputed ==. & inrange(p_gross_household,1,15)

gen HHincomelinear_imputed =.
label var HHincomelinear_imputed "Household Income (Imputed if NA)"
replace HHincomelinear_imputed = 2500 if  HHincomegrp_imputed == 1
replace HHincomelinear_imputed = 7500 if  HHincomegrp_imputed == 2
replace HHincomelinear_imputed = 12500 if  HHincomegrp_imputed == 3
replace HHincomelinear_imputed = 17500 if  HHincomegrp_imputed == 4
replace HHincomelinear_imputed = 22500 if  HHincomegrp_imputed == 5
replace HHincomelinear_imputed = 27500 if  HHincomegrp_imputed == 6
replace HHincomelinear_imputed = 32500 if  HHincomegrp_imputed == 7
replace HHincomelinear_imputed = 37500 if  HHincomegrp_imputed == 8
replace HHincomelinear_imputed = 42500 if  HHincomegrp_imputed == 9
replace HHincomelinear_imputed = 47500 if  HHincomegrp_imputed == 10
replace HHincomelinear_imputed = 55000 if  HHincomegrp_imputed == 11
replace HHincomelinear_imputed = 65000 if  HHincomegrp_imputed == 12
replace HHincomelinear_imputed = 85000 if  HHincomegrp_imputed == 13
replace HHincomelinear_imputed = 125000 if  HHincomegrp_imputed == 14
replace HHincomelinear_imputed = 150000 if  HHincomegrp_imputed == 15

regress HHincomelinear_NA female i.partnered_NA i.agegroup_decades i.workstatus i.nssec_occupclass_NA i.education_imputed i.region_NA [pweight = weight] //* Imputed Version Correlates 0.64 with Real Unimputed Income Estimates (Where We Have Both)
predict syntheticHHincome
replace HHincomelinear_imputed = syntheticHHincome if HHincomelinear_imputed ==.
replace HHincomelinear_imputed = 1 if HHincomelinear_imputed < 1 //* 3 observations predicted negative income shifted to 1.


* Logged HH Income (Non-Imputed Data)
gen HHincomelog_NA = ln(HHincomelinear_NA)	
label var HHincomelog_NA "Household Income Logged (Non-Imputed)"
 
* Logged HH Income (Imputed Data) 
gen HHincomelog_imputed = ln(HHincomelinear_imputed)	
label var HHincomelog_imputed "Household Income Logged (Imputed if NA)"


* Equivalised HH Income Groups (Give all under 18s a 0.3 weight, OECD recommend 0.5 for 14+ but cannot tell age here)

* Raw HH Size, = Missing if = DK
gen hhsize_NA =.
replace hhsize_NA = householdsize_yg if inrange(householdsize_yg,1,8)

* HH Size, if Missing Impute Based on Other BES Data (e.g. Whether Have Children Living with You)
gen hhsize_imputed =.
replace hhsize_imputed = householdsize_yg if inrange(householdsize_yg,1,8)
replace hhsize_imputed = p_hh_size if hhsize_imputed ==. & inrange(p_hh_size,1,8) 
replace hhsize_imputed = 2 if hhsize_imputed ==. & p_hh_children == 1 & partnered_NA == 1
replace hhsize_imputed = 1 if hhsize_imputed ==. & p_hh_children == 1 & partnered_NA == 0
replace hhsize_imputed = 4 if hhsize_imputed ==. & p_hh_children == 3 & partnered_NA == 1
replace hhsize_imputed = 2 if hhsize_imputed ==. & p_hh_children == 1 & partnered_NA == 1
replace hhsize_imputed = 3 if hhsize_imputed ==. & preschoolKidsInHouseW21_ == 1 & schoolKidsInHouseW21_ == 0 & partnered_NA == 1
replace hhsize_imputed = 3 if hhsize_imputed ==. & preschoolKidsInHouseW21_ == 0 & schoolKidsInHouseW21_ == 1 & partnered_NA == 1
replace hhsize_imputed = 4 if hhsize_imputed ==. & preschoolKidsInHouseW21_ == 1 & schoolKidsInHouseW21_ == 1 & partnered_NA == 1
replace hhsize_imputed = 2 if hhsize_imputed ==. & preschoolKidsInHouseW21_ == 1 & schoolKidsInHouseW21_ == 0 & partnered_NA == 0
replace hhsize_imputed = 2 if hhsize_imputed ==. & preschoolKidsInHouseW21_ == 0 & schoolKidsInHouseW21_ == 1 & partnered_NA == 0
replace hhsize_imputed = 3 if hhsize_imputed ==. & preschoolKidsInHouseW21_ == 1 & schoolKidsInHouseW21_ == 1 & partnered_NA == 0
replace hhsize_imputed = 2 if hhsize_imputed ==. & preschoolKidsInHouseW21_ == 0 & schoolKidsInHouseW21_ == 0 & partnered_NA == 1
replace hhsize_imputed = 1 if hhsize_imputed ==. & preschoolKidsInHouseW21_ == 0 & schoolKidsInHouseW21_ == 0 & partnered_NA == 0
replace hhsize_imputed = 2 if hhsize_imputed ==. 

* Number of Under-18s in HH, = Missing if = DK
gen hhchildren_NA =.
replace hhchildren_NA = 1 if hhsize_NA == 1
replace hhchildren_NA = p_hh_children if hhchildren_NA ==. & inrange(p_hh_children,1,6) 
replace hhchildren_NA  = hhchildren_NA  - 1
label define kids_n 0 "No under-18s" 1 "1 under-18" 2 "2 under-18s" 3 "3 under-18s" 4 "4 under-18s" 5 "5+ under-18s", replace
label values hhchildren_NA kids_n

* Number of Under-18s in HH, if Missing Impute Based on Other BES Data (e.g. Whether Have Children Living with You)
gen hhchildren_imputed =.
replace hhchildren_imputed = 1 if hhsize_imputed == 1
replace hhchildren_imputed = p_hh_children if hhchildren_imputed ==. & inrange(p_hh_children,1,6)
replace hhchildren_imputed  = hhchildren_imputed  - 1
label values hhchildren_imputed kids_n
replace hhchildren_imputed = 0 if hhchildren_imputed ==. &  preschoolKidsInHouseW21_  == 0 & schoolKidsInHouseW21_ == 0
replace hhchildren_imputed = 1 if hhchildren_imputed ==. &  preschoolKidsInHouseW21_  == 1 & schoolKidsInHouseW21_ == 0
replace hhchildren_imputed = 1 if hhchildren_imputed ==. &  preschoolKidsInHouseW21_  == 0 & schoolKidsInHouseW21_ == 1
replace hhchildren_imputed = 2 if hhchildren_imputed ==. &  preschoolKidsInHouseW21_  == 1 & schoolKidsInHouseW21_ == 1
replace hhchildren_imputed = 2 if hhchildren_imputed ==. &  preschoolKidsInHouseW21_  == 1 & schoolKidsInHouseW21_ == 1
replace hhchildren_imputed = 0 if hhchildren_imputed ==. & hhsize_imputed  == 1
replace hhchildren_imputed = 1 if hhchildren_imputed ==. & hhsize_imputed  == 2 & partnered_NA == 0
replace hhchildren_imputed = 1 if hhchildren_imputed ==. & inrange(age_yg,40,54)
replace hhchildren_imputed = 0 if hhchildren_imputed ==. & inrange(age_yg,55,99)

* Number of Over-18s in HH
gen otheradults_NA =.
replace otheradults_NA = (hhsize_NA - 1) - hhchildren_NA
replace otheradults_NA = 0 if otheradults_NA < 0

gen otheradults_imputed =.
replace otheradults_imputed = (hhsize_imputed - 1) - hhchildren_imputed
replace otheradults_imputed = 0 if otheradults_imputed < 0
 
 
* Constructing Weights Used to Equivalise HH Income Data - Non-Imputed Data Version
gen adultweight_NA = (otheradults_NA * 0.5) + 1
gen childweight_NA = (hhchildren_NA * 0.3)
gen equivweight_NA = adultweight_NA + childweight_NA

* Constructing Weights Used to Equivalise HH Income Data - Imputed Data Version
gen adultweight_imputed = (otheradults_imputed * 0.5) + 1
gen childweight_imputed = (hhchildren_imputed * 0.3)
gen equivweight_imputed = adultweight_imputed + childweight_imputed	


* Equivalised HH Income (Linear, Logged, and Quintile Group Versions) = Missing if Income/HH Size Data = DK
gen equivHHincomelinear_NA =  HHincomelinear_NA / equivweight_NA	
label var equivHHincomelinear_NA  "Linear HH Income, Adjusted for Size of HH (No Impute)"

gen equivHHincomelog_NA = ln(equivHHincomelinear_NA)
label var equivHHincomelog_NA "Logged HH Income, Adjusted for Size of HH (No Impute)"

xtile equivHHincomequintiles_NA      = equivHHincomelinear_NA [pweight= weight], n(5) //* Quintiles

* Equivalised HH Income (Linear, Logged, and Quintile Group Versions) = Imputed if Income/HH Size Data = DK
gen equivHHincomelinear_imputed =  HHincomelinear_imputed / equivweight_imputed	
label var equivHHincomelinear_imputed  "Linear HH Income, Adjusted for Size of HH (Imputed if NA)"

gen equivHHincomelog_imputed  = ln(equivHHincomelinear_imputed)
label var equivHHincomelog_imputed "Logged HH Income, Adjusted for Size of HH (Imputed if NA)"
replace equivHHincomelog_imputed = 0 if equivHHincomelog_imputed < 0

xtile equivHHincomequintiles_imputed = equivHHincomelinear_imputed [pweight= weight], n(5) //* Quintiles
label var equivHHincomequintiles_imputed "Equivalised HH Income Quintiles (Imputed)"
label define quintiles 1 "Bottom Quintile" 5 "Top Quintile", replace
label values equivHHincomequintiles_NA  equivHHincomequintiles_imputed quintiles



************************************************ HOUSEHOLD CASH SAVINGS

* Linear Raw Household Savings = Missing if DK
gen cashsavings_NA =.
label var cashsavings_NA "Linear HH Savings in Cash (No Impute)"
replace cashsavings_NA = 0  if savings == 0
replace cashsavings_NA = 50 if savingsAmtb == 1
replace cashsavings_NA = 300 if savingsAmtb == 2
replace cashsavings_NA = 750 if savingsAmtb == 3
replace cashsavings_NA = 1500 if savingsAmtb == 4
replace cashsavings_NA = 2500 if savingsAmtb == 5
replace cashsavings_NA = 4000 if savingsAmtb == 6
replace cashsavings_NA = 7500 if savingsAmtb == 7
replace cashsavings_NA = 12500 if savingsAmtb == 8
replace cashsavings_NA = 17500 if savingsAmtb == 9
replace cashsavings_NA = 25000 if savingsAmtb == 10
replace cashsavings_NA = 35000 if savingsAmtb == 11
replace cashsavings_NA = 45000 if savingsAmtb == 12
replace cashsavings_NA = 62500 if savingsAmtb == 13
replace cashsavings_NA = 82500 if savingsAmtb == 14
replace cashsavings_NA = 125000 if savingsAmtb == 15
replace cashsavings_NA = 175000 if savingsAmtb == 16
replace cashsavings_NA = 200000 if savingsAmtb == 17

* Logged Raw Household Savings = Missing if DK
gen logcashsavings_NA = ln(cashsavings_NA + 1)
label var logcashsavings_NA "Logged HH Savings in Cash (No Impute)"

* Household Savings Quartiles (if Have any, = Missing if DK)
xtile cashtercile_NA  = cashsavings_NA if cashsavings_NA != 0 [pweight= weight], n(4) //* Quartiles

* Household Savings Groups - No Savings and then 4 Quartile Groups (= Missing if DK)
gen savingsvalue_NA =.
label var savingsvalue_NA "Savings: 5 Category Version (No Impute)"
label define savingsvalue_NA 1 "No Savings" 2 "Quartile 1 (£1-£7.5k)" 3 "Quartile 2 (£7.51k - £25k)" 4 "Quartile 3 (£25.1k - £82.5k)" 5 "Quartile 4 (£82.51k+)", replace
label values savingsvalue_NA savingsvalue_NA
replace savingsvalue_NA = 1 if cashsavings_NA == 0
replace savingsvalue_NA = 2 if cashtercile_NA == 1
replace savingsvalue_NA = 3 if cashtercile_NA == 2
replace savingsvalue_NA = 4 if cashtercile_NA == 3
replace savingsvalue_NA = 5 if cashtercile_NA == 4

* Household Savings Groups, if Missing Impute Based on Single Imputation using Gender, Relationship, Age, Employment Status, Occupational Class, Education, Region, Home Ownership + HH Value (if Owner) & Equiv. HH Income (V1: Non-Imputed Predictors)
regress cashsavings_NA female i.partnered_NA i.agegroup_decades i.workstatus i.nssec_occupclass_NA i.education_imputed i.region_NA i.HHvaluelinear_NA equivHHincomelinear_NA [pweight = weight] 
predict syntheticHHsavings  //* 0.55 correlation with real thing
replace syntheticHHsavings = 0 if syntheticHHsavings < 0 //* Replace 724 observations predicted negative savings as 0 savings...

* Household Savings Groups, if Missing Impute Based on Single Imputation using Gender, Relationship, Age, Employment Status, Occupational Class, Education, Region, Home Ownership + HH Value (if Owner) & Equiv. HH Income (V2: Imputed Predictors if NA)
regress cashsavings_NA female i.partnered_NA i.agegroup_decades i.workstatus i.nssec_occupclass_NA i.education_imputed i.region_NA i.HHvaluelinear_imp equivHHincomelinear_imp [pweight = weight]  
predict syntheticHHsavings_imp //* 0.53 correlation with real thing
replace syntheticHHsavings_imp = 0 if syntheticHHsavings_imp < 0 

* Household Savings Linear, Imputed if Missing
gen cashsavings_imputed = cashsavings_NA
replace cashsavings_imputed = syntheticHHsavings if cashsavings_imputed ==.
replace cashsavings_imputed = syntheticHHsavings_imp if cashsavings_imputed ==.
label var cashsavings_imp "Linear HH Savings in Cash (Imputed if NA)"

* Household Savings Logged, Imputed if Missing
gen logcashsavings_imputed = ln(cashsavings_imputed + 1)
label var logcashsavings_imp "Logged HH Savings in Cash (Imputed if NA)"

* Household Savings Quartile Groups, Imputed if Missing
xtile cashtercile_imputed  = cashsavings_imputed if cashsavings_imputed != 0 [pweight= weight], n(4) //* Quartiles
gen savingsvalue_imputed =.
label var savingsvalue_imputed "Savings: 5 Category Version (Imputed if NA)"
label define savingsvalue_imputed 1 "No Savings" 2 "Quartile 1 (£1 - £12.5k)" 3 "Quartile 2 (£12.51k - £35k)" 4 "Quartile 3 (£35.1k -£71.3k)" 5 "Quartile 4 (£71.3k+)", replace
label values savingsvalue_imputed savingsvalue_imputed
replace savingsvalue_imputed = 1 if cashsavings_imputed == 0
replace savingsvalue_imputed = 2 if cashtercile_imputed == 1
replace savingsvalue_imputed = 3 if cashtercile_imputed == 2
replace savingsvalue_imputed = 4 if cashtercile_imputed == 3
replace savingsvalue_imputed = 5 if cashtercile_imputed == 4

drop hhsize_NA hhsize_imputed hhchildren_NA hhchildren_imputed otheradults_NA otheradults_imputed adultweight_NA childweight_NA equivweight_NA adultweight_imputed childweight_imputed equivweight_imputed syntheticHHsavings syntheticHHsavings_imp syntheticHHincome



************************************************ SUBJECTIVE EVALUATIONS OF FINANCIAL WELLBEING OF DIFFERENT AGE GROUPS WITHIN THE FAMILY


* Linear Version (Missing if = DK/No Family that Age)
gen financesFam20s = financesFam_20s if financesFam_20s < 11
gen financesFam40s = financesFam_40s if financesFam_40s < 11
gen financesFam60s = financesFam_60s if financesFam_60s < 11
label define financial 0 "Doing Very Badly" 10 "Doing Very Well"
label values  financesFam20s financesFam40s financesFam60s financial
label var financesFam20s "Perceived average financial wellbeing of close family aged 18-39 (if have family)"
label var financesFam40s "Perceived average financial wellbeing of close family aged 40-59 (if have family)"
label var financesFam60s "Perceived average financial wellbeing of close family aged 60-99 (if have family)"

* Grouped Version (Coded 4 if = DK/No Family that Age)
gen financesFam20group =.
label var financesFam20group "Ratings of 18-39 Family Finances: 4 Groups, inc. DK/NA"
replace financesFam20group = 1 if inrange(financesFam20s,0,4)
replace financesFam20group = 2 if financesFam20s== 5
replace financesFam20group = 3 if inrange(financesFam20s,6,10)
replace financesFam20group = 4 if financesFam20s ==.

gen financesFam40group =.
label var financesFam40group "Ratings of 40-59 Family Finances: 4 Groups, inc. DK/NA"
replace financesFam40group = 1 if inrange(financesFam40s,0,4)
replace financesFam40group = 2 if financesFam40s== 5
replace financesFam40group = 3 if inrange(financesFam40s,6,10)
replace financesFam40group = 4 if financesFam40s ==.

gen financesFam60group =.
label var financesFam60group "Ratings of 60+ Family Finances: 4 Groups, inc. DK/NA"
replace financesFam60group = 1 if inrange(financesFam60s,0,4)
replace financesFam60group = 2 if financesFam60s== 5
replace financesFam60group = 3 if inrange(financesFam60s,6,10)
replace financesFam60group = 4 if financesFam60s ==.

label define famgroup 1 "Badly" 2 "Midpoint" 3 "Well" 4 "Don't Know / No Younger Relatives" 
label values financesFam20group financesFam40group financesFam60group famgroup

* Dummy Variable Version (Coded 1 if Have a Relative Doing Badly in that Age Group)
gen strugglefam20 =.
replace strugglefam20 = 1 if financesFam20group == 1
replace strugglefam20 = 0 if inlist(financesFam20group,2,3,4)
label var strugglefam20  "Has Financially Struggling Relatives Aged 18-39 Dummy"

gen strugglefam40 =.
replace strugglefam40 = 1 if financesFam40group == 1
replace strugglefam40 = 0 if inlist(financesFam40group,2,3,4)
label var strugglefam40  "Has Financially Struggling Aged 40-59 Dummy"

gen strugglefam60 =.
replace strugglefam60 = 1 if financesFam60group == 1
replace strugglefam60 = 0 if inlist(financesFam60group,2,3,4)
label var strugglefam60  "Has Financially Struggling Aged 60+ Dummy"



************************************************ SUBJECTIVE EVALUATIONS OF RISK THAT SELF WILL NEED TO ASSIST YOUNG ADULT OR OLDER ADULT RELATIVES

* Risk Help Relative Aged 60+ = Missing if  DK
recode risk10_helpOld (1 = 1 "Very Unlikely") (2=2) (3=3) (4=4) (5 = 5 "Very Likely") (else=.), gen(riskElderly_lin)
label var riskElderly_lin "10 Year Risk: Give sig. financial/practical help to family member aged 60+ (exc. DK)"

* Risk Help Relative Aged 18-39 = Missing if  DK
recode risk10_helpYoung (1 = 1 "Very Unlikely") (2=2) (3=3) (4=4) (5 = 5 "Very Likely") (else=.), gen(riskYouth_lin)
label var riskYouth_lin "10 Year Risk: Give sig. financial/practical help to family member aged 18-39 (exc. DK)"



************************************************ POLICY ATTITUDES - ABSOLUTE SUPPORT FOR PRO-YOUTH POLICIES


* Policy Preferences, Recode as Missing if = DK
foreach var of varlist  support_pension support_eldercare support_childcare support_vocateduc support_unieduc support_renewables support_affordhousing support_govhousing support_schoolmeal support_elderactivity priority_youngVold ///
agree_educVpensions{
        replace `var' =. if `var' == 99
}

* Scale for Young Adult-Oriented Policy Support (1-5, = Missing if = DK)
alpha support_childcare support_vocateduc support_unieduc support_affordhousing support_govhousing //* Scale reliability = 0.78

gen youthpol_scale =.
label var youthpol_scale "Average Support for 5 Social Policies Aimed at Young Adults"
label define scale 1 "Least Supportive" 5 "Most Supportive", replace
label values youthpol_scale scale
replace youthpol_scale = (support_childcare + support_vocateduc + support_unieduc + support_affordhousing + support_govhousing) / 5




************************************************ POLICY ATTITUDES - RELATIVE SUPPORT FOR PRO-YOUTH & PRO-OLD POLICIES (E.G. TRADE-OFF TASKS)

foreach var of varlist  priority_pensions priority_eldercare priority_eldertransport priority_winterfuel priority_affordhousing priority_childcare priority_vocateduc priority_unieduc priority_renewables priority_borderforce {
        replace `var' = 0 if `var' == 2
		replace `var' = 1 if `var' == 1
		replace `var' = . if `var' == 99 
} //* Replace = Missing if = DK

label define prority_var 0 "Not a Top 3 Priority" 1 "A Top 3 Priority", replace
label values priority_pensions priority_eldercare priority_eldertransport priority_winterfuel priority_affordhousing priority_childcare priority_vocateduc priority_unieduc priority_renewables priority_borderforce prority_var
 
gen nYARP =.
label var nYARP  "Number of Young Adult Policies Prioritised"
replace nYARP = priority_affordhousing + priority_childcare + priority_vocateduc + priority_unieduc 

gen nOARP =.
label var nOARP  "Number of Older Adult Policies Prioritised"
replace nOARP =  priority_pensions + priority_eldercare + priority_eldertransport + priority_winterfuel

gen priority_nYARP =.
label var priority_nYARP  "At Least One Young Adult Policies Prioritised"
replace priority_nYARP = 1 if nYARP > 0 &  nYARP !=.
replace priority_nYARP = 0 if nYARP == 0 &  nYARP !=.

gen priority_nOARP =.
label var priority_nOARP  "At Least One Older Adult Policies Prioritised"
replace priority_nOARP = 1 if nOARP > 0 &  nOARP !=.
replace priority_nOARP = 0 if nOARP == 0 &  nOARP !=.



************************************************ POLICY ATTITUDES - ABSTRACT SCALE OF PREFERRING SPENDING ON YOUNG ADULTS OR OLDER ADULTS (E.G. ALTERNATIVE TRADE-OFF TASKS)

replace priority_youngVold =. if priority_youngVold == 99 //* = Missing if = DK



************************************************ POLICY ATTITUDES - GENERAL TAX-SPEND PREFERENCES ***************************************************

recode taxSpendSelf  (10 = 10 "Increase Taxes + Spend More") (9 = 9) (8 = 8) (7 = 7) (6 = 6) (5 = 5) (4 = 4) (3 = 3) (2 = 2) (1 = 1) (0 = 0  "Cut Taxes and Spend Less") (else=.), gen(BES_selfproTaxSpend_lin)
label var BES_selfproTaxSpend_lin "Self: Pro-Higher Taxes and Spending Scale (0-10)"	 //* Recoded = Missing if = DK	

recode taxSpendSelf  (0/4 = 3 "Decrease Tax/Spend Less") (5 = 2 "Midpoint") (6/10 = 1 "Increase Tax/Spend More") (9999 = 4 "Don't Know"), gen(BES_selfTaxSpend_grp)
label var BES_selfTaxSpend_grp "Self: Pro or Anti More Tax/Spend Generally (Grp Version)"	 //* Recoded = 4 if = DK	



************************************************ POLICY ATTITUDES - GENERAL IMMIGRATION PREFERENCES ***************************************************

recode immigSelf  (10 = 10  "Increase Immigration")  (9 = 9) (8 = 8) (7 = 7) (6 = 6) (5 = 5) (4 = 4) (3 = 3) (2 = 2) (1 = 1) (0 = 0  "Decrease Immigration") (else=.), gen(BES_selfproImmig_lin) 
label var BES_selfproImmig_lin "Self: Pro-Increased Immigration Scale (0-10)"		//* Recoded = Missing if = DK	

recode immigSelf (0/4 = 3 "Decrease Tax/Spend Less") (5 = 2 "Midpoint") (6/10 = 1 "Increase Tax/Spend More") (9999 = 4 "Don't Know"), gen(BES_selfImmig_grp)
label var BES_selfImmig_grp "Self: Pro or Anti More Immigration Generally (Grp Version)"	 //* Recoded = 4 if = DK	



************************************************ GENERAL SOCIOTROPIC (NATIONAL) ECONOMIC EVALUATIONS SCALE ***************************************************


replace econGenProsp   =. if econGenProsp == 9999  //* Prospective economic evaluations next 12 months (higher = things get better) - Replace = Missing if = DK
replace econGenRetro   =. if econGenRetro  == 9999  //* Retrospective economic evaluations previous 12 months (higher = things got better) - Replace = Missing if = DK

gen BES_nationalEconEvalCombo = (econGenProsp + econGenRetro) - 1  //* Scale of Economic Evaluations (Higher = Things Got Better and Will Continue to do So) = Missing if = DK
label var BES_nationalEconEvalCombo "National Economic Evaluation Scale, Prospective + Retrospective (1-9)"


************************************************ GENERAL POCKETBOOK (PERSONAL) ECONOMIC EVALUATIONS SCALE ***************************************************


replace econPersonalProsp =. if econPersonalProsp == 9999	//* Prospective economic evaluations next 12 months (higher = things get better) - Replace = Missing if = DK
replace econPersonalRetro =. if econPersonalRetro == 9999	//* Retrospective economic evaluations previous 12 months (higher = things got better) - Replace = Missing if = DK
	
gen BES_personalEconEvalCombo = (econPersonalRetro + econPersonalProsp) - 1  //* Scale of Economic Evaluations (Higher = Things Got Better and Will Continue to do So) = Missing if = DK
label var BES_personalEconEvalCombo "Personal Economic Evaluation Scale, Prospective + Retrospective (1-9)"

label define EconEvalCombo 1 "Got Much Worse, Will Get Much Worse" 9 "Got Much Better, Will Get Much Better", replace 
label values BES_personalEconEvalCombo BES_nationalEconEvalCombo EconEvalCombo



************************************************ OBJECTIVE ASSETS OF ONE'S CHILDREN / GRANDCHILDREN ***************************************************

* Number of Children
gen children_totalN =. 
label var children_totalN "How many children do you have, inc. step children?" 
replace children_totalN = 0 if hasChild == 1
replace children_totalN = 1 if hasChild == 2
replace children_totalN = 2 if hasChild == 3
label define childN 0 "No Children" 1 "1 Child" 2 "2+ Children", replace
label values children_totalN childN

* Dummy variable = 1 if have a grandchild
gen grandchild =.
label var grandchild "Has a grandchild"
label define grandchild 0 "No Grandchildren" 1 "Has a Grandchild", replace 
label values grandchild grandchild
replace grandchild = 0 if hasGrandchild == 1
replace grandchild = 1 if hasGrandchild == 2

* Age of Eldest Child (or Only Child if Applicable)
gen olderchild_age =.
label var olderchild_age "Age of Oldest Child (or Only Child)"
label define olderchild1 1 "Under-18" 2 "18-39" 3 "40+" 99 "NA - No Children", replace
label values olderchild_age olderchild1
replace olderchild_age = 1 if onlyChild_under18 == 1 & onlyChild_over40 == 2 | elderChild_under18 == 1 & elderChild_over40 == 2
replace olderchild_age = 2 if onlyChild_under18 == 2 & onlyChild_over40 == 2 | elderChild_under18 == 2 & elderChild_over40 == 2
replace olderchild_age = 3 if onlyChild_under18 == 2 & onlyChild_over40 == 1 | elderChild_under18 == 2 & elderChild_over40 == 1 
replace olderchild_age = 99 if children_totalN == 0

* Age of Youngest Child (or Only Child if Applicable)
gen youngerchild_age =.
label var youngerchild_age "Age of Oldest Child (or Only Child)"
label define youngerchild1 1 "Under-18" 2 "18-39" 3 "40+" 99 "NA - No Children", replace
label values youngerchild_age youngerchild1
replace youngerchild_age = 1 if youngerChild_under18 == 1 & youngerChild_over40 == 2
replace youngerchild_age = 2 if youngerChild_under18 == 2 & youngerChild_over40 == 2
replace youngerchild_age = 3 if youngerChild_under18 == 2 & youngerChild_over40 == 1 
replace youngerchild_age = 99 if children_totalN == 0

* Age of Eldest Grandchild (or Only Grandchild if Applicable)
gen grandchild_age =.
label var grandchild_age "Age of Oldest Grandchild (or Only Grandchild)"
label define grandchild_age1 1 "Under-18" 2 "18-39" 3 "40+" 99 "NA - No Grandchildren", replace
label values grandchild_age grandchild_age1
replace grandchild_age = 1 if grandChild_under18 == 1 & grandChild_over40 == 2
replace grandchild_age = 2 if grandChild_under18 == 2 & grandChild_over40 == 2
replace grandchild_age = 3 if grandChild_under18 == 2 & grandChild_over40 == 1
replace grandchild_age = 99 if grandchild == 0

* Dummy = 1 if Have a Child Aged 18-39
gen haschild1839 =.
label var haschild1839 "Dummy: Has Child aged 18-39"
replace haschild1839 = 1 if olderchild_age == 2 | youngerchild_age == 2
replace haschild1839 = 0 if olderchild_age != 2 & youngerchild_age != 2 & olderchild_age !=.

* Dummy = 1 if Have Multiple Children Aged 18-39
gen multichild1839 =.
label var multichild1839 "Dummy: Multiple Children Aged 18-39"
replace multichild1839 = 1 if olderchild_age == 2 & youngerchild_age == 2
replace multichild1839 = 0 if multichild1839 != 1

* Dummy = 1 if Have a Grandchild Aged 18-39
gen hasgrandchild1839 =.
label var hasgrandchild1839 "Dummy: Has Grandchild  aged 18-39"
replace hasgrandchild1839 = 1 if grandchild_age == 2 
replace hasgrandchild1839 = 0 if inlist(grandchild_age,1,3,99)

* Dummy = 1 if Have a Child or Grandchild Aged 18-39
gen haschildORgrandchild1839 =.
label var haschildORgrandchild1839 "Dummy: Has Child or Grandchild aged 18-39"
replace haschildORgrandchild1839 = 1 if haschild1839 == 1 | hasgrandchild1839 == 1
replace haschildORgrandchild1839 = 0 if haschild1839 == 0 & hasgrandchild1839 == 0

* Eldest Child Education Dummy, = 1 if Eldest Child (or Only Child) Has a Uni Degree
gen olderchild_degree =.
label var olderchild_degree "Older Child has a Degree (if has child)"
label define childhas 1 "Yes" 0 "No", replace
label values olderchild_degree childhas
replace olderchild_degree = 1 if onlyChild_degree == 1 | elderChild_degree  == 1
replace olderchild_degree = 0 if onlyChild_degree == 2 | elderChild_degree  == 2

* Eldest Child Property Dummy, = 1 if Eldest Child (or Only Child) Has UK Property (inc. with a Mortgage)
gen olderchild_property =.
label var olderchild_property "Older Child has a Degree (if has child)"
label values olderchild_property childhas
replace olderchild_property = 1 if onlyChild_house == 1 | elderChild_house  == 1
replace olderchild_property = 0 if onlyChild_house == 2 | elderChild_house  == 2

* Eldest Child Total Age & Assets Group Variable 
gen olderchild_assetsSIMP =.
label var olderchild_assetsSIMP "Eldest Child Age & Assets (Simplified)"
label define chilcat2 1 "18-39: No Property + No Degree" 2 "18-39: No Property + Degree" 3 "18-39: Property + No Degree" 4 "18-39: Property + Degree" 5 "No Eldest Child Aged 18-39", replace
label values olderchild_assetsSIMP chilcat2
replace olderchild_assetsSIMP = 1 if olderchild_age == 2 & olderchild_degree == 0 & olderchild_property == 0
replace olderchild_assetsSIMP = 2 if olderchild_age == 2 & olderchild_degree == 1 & olderchild_property == 0
replace olderchild_assetsSIMP = 3 if olderchild_age == 2 & olderchild_degree == 0 & olderchild_property == 1
replace olderchild_assetsSIMP = 4 if olderchild_age == 2 & olderchild_degree == 1 & olderchild_property == 1
replace olderchild_assetsSIMP = 5 if olderchild_age != 2 & olderchild_age !=.


************************************************ PARTISANSHIP ***************************************************


* Partisanship (Long)

recode partyId (1 = 1 "Conservative") (2 = 2 "Labour") (3 = 3 "Lib Dem") (4 = 4 "SNP/PC") (5 = 4) (7 = 5 "Greens") (12 = 6 "Brexit") (9 = 7 "Other") (10 = 8 "None") (9999 = 9 "Don't Know") (else=.), gen(partyID_BES)
label var partyID_BES "Partisanship (inc. Squeezes - BES Wave 23)"

replace partyID_BES = 1 if partyIdSqueeze == 1 //* Follow-up question asked those with no party ID if there was a party they felt closer to than others. Also count these as partisans.
replace partyID_BES = 2 if partyIdSqueeze == 2
replace partyID_BES = 3 if partyIdSqueeze == 3
replace partyID_BES = 4 if partyIdSqueeze == 4
replace partyID_BES = 4 if partyIdSqueeze == 5
replace partyID_BES = 5 if partyIdSqueeze == 7
replace partyID_BES = 6 if partyIdSqueeze == 12
replace partyID_BES = 7 if partyIdSqueeze == 9
replace partyID_BES = 8 if partyIdSqueeze == 10
replace partyID_BES = 9 if partyIdSqueeze == 9999
replace partyID_BES = 2 if partyID_BES ==. & partyID_yg == 2
replace partyID_BES = 4 if partyID_BES ==. & partyID_yg == 4
replace partyID_BES = 8 if partyID_BES ==. & partyID_yg == 6

* Partisanship (Short)
recode partyID_BES (1 = 1 "Conservative") (2 = 2 "Labour") (3 = 3 "Lib Dem") (4/7 = 4 "Other") (8 = 5 "None") (9 = 6 "Don't Know") (else=.), gen(shortpartyID_w23)
label var shortpartyID_w23  "Partisanship, Simplified (inc. Squeezes - BES Wave 23)"




************************************************ VOTE INTENTION ***************************************************

*** Vote Intention in August 2022 (Short Version)
gen	SIMPintendedvote_2022 = .
label var SIMPintendedvote_2022 "Simplified Intended Vote (Future Election)"
label define SIMPintendedvote_2022 1 "Conservative" 2 "Labour" 3 "Other Party" 4 "Would not Vote" 5 "Don't Know/Refused", replace
label values SIMPintendedvote_2022 SIMPintendedvote_2022
replace SIMPintendedvote_2022 = 1 if voteintent2022 == 1	
replace SIMPintendedvote_2022 = 2 if voteintent2022 == 2		
replace SIMPintendedvote_2022 = 3 if inrange(voteintent2022,3,8)
replace SIMPintendedvote_2022 = 4 if voteintent2022  == 9
replace SIMPintendedvote_2022 = 5 if voteintent2022  == 98 | voteintent2022 == 99


*** Vote Intention in August 2022 (Longer Version)
gen LONGintendedvote_2022 =.
label var LONGintendedvote_2022 "Longer Inteded Vote Variable (Future Election)"
label define LONGintendedvote_2022 1 "Conservative" 2 "Labour" 3 "Liberal Democrat" 4 "SNP/PC" 5 "Green Party" 6 "Reform UK" 7 "Other Party" 8 "Would not Vote" 9 "Don't Know"
label values LONGintendedvote_2022 LONGintendedvote_2022

replace LONGintendedvote_2022 = 1 if voteintent2022 == 1
replace LONGintendedvote_2022 = 2 if voteintent2022 == 2
replace LONGintendedvote_2022 = 3 if voteintent2022 == 3
replace LONGintendedvote_2022 = 4 if voteintent2022 == 4 | voteintent2022 == 5
replace LONGintendedvote_2022 = 5 if voteintent2022 == 7
replace LONGintendedvote_2022 = 6 if voteintent2022 == 6
replace LONGintendedvote_2022 = 7 if voteintent2022 == 8
replace LONGintendedvote_2022 = 8 if voteintent2022 == 9
replace LONGintendedvote_2022 = 9 if voteintent2022 == 99

*** Vote Intention in August 2022 (Support Incumbent Conservatives vs. Some Other Party)
recode SIMPintendedvote_2022 (1 = 1 "Conservative") (2/3 = 0 "Other") (else =.), gen(vote_OtherCon)
label var vote_OtherCon "Vote Intention: Conservatives (1) V Any Other Party (0)"


************************************************ EVALUATIONS OF CONSERVATIVE REPRESENTATION OF YOUNG/OLD ***************************************************

* Evaluation of How Closely Conservatives Represent the Retired (Higher = More Closely; = Missing if = DK)
replace conLookAfterRetired =. if conLookAfterRetired == 9999

* Evaluation of How Closely Conservatives Represent Young People (Higher = More Closely; = Missing if = DK)
replace conLookAfterYoung =. if conLookAfterYoung == 9999



**************************************************************************************************************************************************************


*** FINAL CLEAN-UP (KEEP ONLY VARIABLES USED IN THE 'FAMILY MATTERS' BJPS STUDY) ***

keep id response_date weight age_yg  age10 agegroup_decades aged60plus ethnicity_NA ethnicity_imputed education_NA unidegree_NA education_imputed unidegree_imputed female workstatus nssec_occupclass_NA region_NA housevalue_logged_imputed housevalue_logged_NA homevaluegrp_NA HHvaluelinear_impute HHvaluelinear_NA homevaluegrp_imputed partnered_NA HHincomegrp_NA HHincomelinear_NA HHincomegrp_imputed HHincomelinear_imputed HHincomelog_NA HHincomelog_imputed equivHHincomelinear_NA equivHHincomelinear_imputed equivHHincomelog_NA equivHHincomelog_imputed equivHHincomequintiles_NA equivHHincomequintiles_imputed cashsavings_NA logcashsavings_NA savingsvalue_NA cashsavings_imputed logcashsavings_imputed savingsvalue_imputed financesFam20s financesFam40s financesFam60s financesFam20group financesFam40group financesFam60group strugglefam20 strugglefam40 strugglefam60 haschild1839 hasgrandchild1839 haschildORgrandchild1839 riskElderly_lin riskYouth_lin youthpol_scale nYARP nOARP priority_nYARP priority_nOARP BES_selfproTaxSpend_lin BES_selfTaxSpend_grp BES_selfproImmig_lin BES_selfImmig_grp BES_nationalEconEvalCombo BES_personalEconEvalCombo olderchild_assets olderchild_assetsSIMP partyID_BES shortpartyID_w23 SIMPintendedvote_2022 vote_OtherCon support_pension support_eldercare support_childcare support_vocateduc support_unieduc support_renewables support_affordhousing support_govhousing support_schoolmeal support_elderactivity priority_youngVold priority_youngVold priority_pensions priority_eldercare priority_eldertransport priority_winterfuel priority_affordhousing priority_childcare priority_vocateduc priority_unieduc priority_renewables priority_borderforce riskElderly_lin riskYouth_lin eurefchoice2016_yg  socialgrade_NA conLookAfterRetired conLookAfterYoung agree_educVpensions econGenProsp econGenRetro leftrightscaleID_yg

order id response_date weight age_yg  age10 agegroup_decades aged60plus ethnicity_NA ethnicity_imputed education_NA unidegree_NA education_imputed unidegree_imputed female workstatus nssec_occupclass_NA socialgrade_NA region_NA housevalue_logged_imputed housevalue_logged_NA homevaluegrp_NA HHvaluelinear_impute HHvaluelinear_NA homevaluegrp_imputed partnered_NA HHincomegrp_NA HHincomelinear_NA HHincomegrp_imputed HHincomelinear_imputed HHincomelog_NA HHincomelog_imputed equivHHincomelinear_NA equivHHincomelinear_imputed equivHHincomelog_NA equivHHincomelog_imputed equivHHincomequintiles_NA equivHHincomequintiles_imputed cashsavings_NA logcashsavings_NA savingsvalue_NA cashsavings_imputed logcashsavings_imputed savingsvalue_imputed financesFam20s financesFam40s financesFam60s financesFam20group financesFam40group financesFam60group strugglefam20 strugglefam40 strugglefam60 haschild1839 hasgrandchild1839 haschildORgrandchild1839 olderchild_assets olderchild_assetsSIMP  riskElderly_lin riskYouth_lin youthpol_scale nYARP nOARP priority_nYARP priority_nOARP agree_educVpensions BES_nationalEconEvalCombo BES_personalEconEvalCombo partyID_BES shortpartyID_w23 SIMPintendedvote_2022 vote_OtherCon conLookAfterYoung conLookAfterRetired support_pension support_eldercare support_childcare support_vocateduc support_unieduc support_renewables support_affordhousing support_govhousing support_schoolmeal support_elderactivity priority_youngVold priority_youngVold priority_pensions priority_eldercare priority_eldertransport priority_winterfuel priority_affordhousing priority_childcare priority_vocateduc priority_unieduc priority_renewables priority_borderforce conLookAfterRetired conLookAfterYoung agree_educVpensions econGenProsp econGenRetro leftrightscaleID_yg BES_selfproTaxSpend_lin BES_selfTaxSpend_grp BES_selfproImmig_lin BES_selfImmig_grp  eurefchoice2016_yg



STOP

save FamilyMatters_ReplicationData_Cleaned, replace


